home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 4.9 KB | 173 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWRecevr.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWRECEVR_H
- #include "FWRecevr.h"
- #endif
-
- #ifndef FWNOTIFR_H
- #include "FWNotifr.h"
- #endif
-
- #ifndef FWINTERE_H
- #include "FWIntere.h"
- #endif
-
- //======================================================================================
- // Interest Matching Proc
- //======================================================================================
-
- static FW_Boolean FW_InterestMatchProc(const void* v1, const void* v2)
- {
- FW_CInterest* i1 = (FW_CInterest*) v1;
- FW_CInterest* i2 = (FW_CInterest*) v2;
-
- return (*i1 == *i2);
- }
-
- //========================================================================================
- // CLASS FW_MReceiver
- //========================================================================================
-
- FW_DEFINE_CLASS_M0(FW_MReceiver)
- FW_DEFINE_AUTO(FW_MReceiver)
-
- //----------------------------------------------------------------------------------------
- // FW_MReceiver::FW_MReceiver
- //----------------------------------------------------------------------------------------
-
- FW_MReceiver::FW_MReceiver() :
- fIsConnected(TRUE),
- fInterestList(FW_InterestMatchProc)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MReceiver::~FW_MReceiver
- //----------------------------------------------------------------------------------------
-
- FW_MReceiver::~FW_MReceiver()
- {
- FW_START_DESTRUCTOR
-
- RemoveAllInterests();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MReceiver::AddInterest
- //----------------------------------------------------------------------------------------
-
- void FW_MReceiver::AddInterest(const FW_CInterest& interest)
- {
- // Check that the interest is not already registered
- if (fInterestList.Contains(&interest))
- return;
-
- FW_CInterest* interestCopy = new FW_CInterest(interest);
-
- if (fIsConnected)
- interestCopy->GetNotifier()->AddReceiver(this, interestCopy);
-
- fInterestList.AddLast(interestCopy);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MReceiver::RemoveAllInterests
- //----------------------------------------------------------------------------------------
-
- void FW_MReceiver::RemoveAllInterests()
- {
- FW_CInterest* anInterest;
-
- if (fIsConnected)
- {
- FW_TOrderedCollectionIterator<FW_CInterest> ite(&fInterestList);
- for (anInterest = ite.First(); ite.IsNotComplete(); anInterest = ite.Next())
- {
- anInterest->GetNotifier()->RemoveReceiver(this, *anInterest);
- }
- }
-
- while ((anInterest = fInterestList.First()) != NULL)
- {
- fInterestList.Remove(anInterest);
- delete anInterest;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MReceiver::RemoveInterest
- //----------------------------------------------------------------------------------------
-
- void FW_MReceiver::RemoveInterest(const FW_CInterest& interest)
- {
- FW_TOrderedCollection<FW_CInterest> temp;
-
- FW_CInterest* anInterest;
-
- FW_TOrderedCollectionIterator<FW_CInterest> ite1(&fInterestList);
- for (anInterest = ite1.First(); ite1.IsNotComplete(); anInterest = ite1.Next())
- {
- if (*anInterest == interest)
- temp.AddLast(anInterest);
- }
-
- FW_TOrderedCollectionIterator<FW_CInterest> ite2(&temp);
- for (anInterest = ite2.First(); ite2.IsNotComplete(); anInterest = ite2.Next())
- {
- fInterestList.Remove(anInterest);
-
- if (fIsConnected)
- anInterest->GetNotifier()->RemoveReceiver(this, *anInterest);
-
- delete anInterest;
- }
-
- // [HLX] no need to remove from temp. FW_CInterestCollection::__dt calls RemoveAll
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MReceiver::Connect
- //----------------------------------------------------------------------------------------
-
- void FW_MReceiver::Connect()
- {
- if (!fIsConnected)
- {
- FW_TOrderedCollectionIterator<FW_CInterest> ite(&fInterestList);
- for (FW_CInterest* anInterest = ite.First(); ite.IsNotComplete(); anInterest = ite.Next())
- {
- anInterest->GetNotifier()->AddReceiver(this, anInterest);
- }
- }
-
- fIsConnected = TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MReceiver::Disconnect
- //----------------------------------------------------------------------------------------
-
- void FW_MReceiver::Disconnect()
- {
- if (fIsConnected)
- {
- FW_TOrderedCollectionIterator<FW_CInterest> ite(&fInterestList);
- for (FW_CInterest* anInterest = ite.First(); ite.IsNotComplete(); anInterest = ite.Next())
- {
- anInterest->GetNotifier()->RemoveReceiver(this, *anInterest);
- }
- }
-
- fIsConnected = FALSE;
- }
-